package com.util;

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;


public class TokenUtil {
    private TokenUtil(){};
    private static final TokenUtil instance = new TokenUtil();

    public static TokenUtil getInstance(){
        return instance;
    }

    // 生成Token
    public static String makeToken(){
        String token = (System.currentTimeMillis() + new Random().nextInt(999999999)) + "";
        try {
            MessageDigest md = MessageDigest.getInstance("md5");
            byte md5[] =  md.digest(token.getBytes());
            Base64 encoder = new Base64();
            return new String(encoder.encode(md5));
        } catch (NoSuchAlgorithmException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
}
